package com.xnyzc.lhy.mis.controller.cmsapi.activity;


import com.xnyzc.lhy.common.entity.ActivityRv;
import com.xnyzc.lhy.common.exception.ActivityException;
import com.xnyzc.lhy.common.penum.activity.ActivityErrorCode;
import com.xnyzc.lhy.mis.service.activity.IOaSysActivityPeriodService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 活动周期 前端控制器
 * </p>
 *
 * @author haoyfa
 * @since 2019-12-16
 */
@RestController
@RequestMapping("/activity/activityPeriod")
@Slf4j
public class OaSysActivityPeriodController {
    @Autowired
    IOaSysActivityPeriodService iOaSysActivityPeriodService;

    /**
     * 活动周期完成
     * 定时任务调用，每天凌晨4点执行
     *
     * @return
     */
    @ApiOperation(value = "活动周期完成", notes = "活动周期完成")
    @PostMapping(value = "/completeActivityPeriod")
    public ActivityRv completeActivityPeriod() {
        try {
            log.info("===========开始活动周期完成==========");
            iOaSysActivityPeriodService.completeActivityPeriod();
            log.info("===========结束活动周期完成==========");
            return ActivityRv.wrapSuccess();
        } catch (ActivityException ae) {
            log.error("活动周期完成-失败：" + ae.getErrno().getDesc());
            return ActivityRv.wrapErrorCode(ae.getErrno());
        } catch (Exception ex) {
            log.error("活动周期完成-失败" + ActivityErrorCode.unKnow.getDesc());
            return ActivityRv.wrapErrorCode(ActivityErrorCode.unKnow);
        }
    }

    @ApiOperation(value = "活动周期结算", notes = "活动周期结算")
    @PostMapping(value = "/calActivityPeriodReward")
    public ActivityRv calActivityPeriodReward() {
        try {
            log.info("===========开始活动周期结算==========");
            iOaSysActivityPeriodService.calActivityPeriodReward();
            log.info("===========结束活动周期结算==========");
            return ActivityRv.wrapSuccess();
        } catch (ActivityException ae) {
            log.error("活动周期结算-失败：" + ae.getErrno().getDesc());
            return ActivityRv.wrapErrorCode(ae.getErrno());
        } catch (Exception ex) {
            log.error("活动周期结算-失败" + ActivityErrorCode.unKnow.getDesc());
            return ActivityRv.wrapErrorCode(ActivityErrorCode.unKnow);
        }
    }
}
